<!DOCTYPE HTML>
<html class="error-page no-js" lang="zh_CN">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

<title>代码生成器1.0</title> #required_css
</head>

<body>
	<div class="center-wrapper">
		<div class="center-content text-center">
			<div class="row no-m">
				<div class="col-xs-10 col-xs-offset-2 col-sm-10 col-sm-offset-6 col-md-8 col-md-offset-2">
					<form action="$!basePath/open/dev/code/step/4" method="post" class="form-horizontal" onsubmit="return check()">
						<input type="hidden" name="catalog" value="$!catalog"/>
						<input type="hidden" name="tables" value="$!tables"/>
						<input type="hidden" name="columnMapping" value=""/>
						<section class="panel bg-white no-b fadeIn animated shadow">
							<div class="panel-heading">
								<h2>参数设置</h2>
								<h4>3/4</h4>
							</div>
							<div class="panel-body text-left" style="height:400px; overflow: auto;">
								<div class="col-md-4">
									<div class="form-group">
										<label class="col-sm-5 control-label">包前缀</label>
										<div class="col-lg-7">
											<input type="text" name="packagePrefix" class="form-control" value="com.jrelax.web"/>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-5 control-label">包名</label>
										<div class="col-lg-7">
											<input type="text" name="packageName" class="form-control" value="$!pack"/>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-5 control-label">保存路径</label>
										<div class="col-lg-7">
											<input type="text" name="savePath" class="form-control" value="$!savePath"/>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-5 control-label">移除表前缀</label>
										<div class="col-lg-7">
											<input type="text" name="tablePrefix" class="form-control" value="$!prefix"/>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-5 control-label">实体类保持前缀</label>
										<div class="col-lg-7">
											<input type="checkbox" name="entityKeepPrefix" data-switch-blue checked/>
										</div>
									</div>
								</div>
								<div class="col-md-8">
									<div class="form-group">
										<div class="col-md-12">
											#foreach($!table in $!tableColumns.entrySet())
												<table class="table table-bordered table-striped mapping" name="$!table.key">
													<thead>
														<tr>
															<th colspan="$!table.value.size()" class="text-center">
																字段映射：$!table.key
															</th>
														</tr>
													</thead>
													<tbody>
														#foreach($!column in $!table.value.entrySet())
														<tr>
															<td>
																<input name="column" class="form-control" type="text" disabled="disabled" value="$!column.key"/>
															</td>
															<td>
																<input name="display" class="form-control" type="text" value="$!column.value"/>
															</td>
														</tr>
														#end
													</tbody>
												</table>
											#end
										</div>
									</div>
								</div>
							</div>
							<div class="panel-footer">
								<button class="btn btn-primary">下一步</button>
							</div>
						</section>
					</form>
				</div>
			</div>
		</div>
	</div>
	#required_js
	<script src="$!basePath/framework/js/form/form.js"></script>
	<script type="text/javascript">
		$(function(){
			$("table>tbody input[name='display']").each(function(i,n){
				var text = $(n).val();
				text = text.replace("id", "ID");
				text = text.replace("createUser", "创建人");
				text = text.replace("createTime", "创建时间");
				text = text.replace("lastModifyTime", "最后更新时间");
				$(n).val(text);
			});
			$("table>tbody input[name='display']").bind("keyup", function(e){
				if(e.keyCode == 40){//down
					var nextTr = $(this).parent().parent().next();
					if(nextTr[0] != undefined){
						nextTr.find("input").last().focus().select();
					}
				}else if(e.keyCode == 38){//up
					var prevTr = $(this).parent().parent().prev();
					if(prevTr[0] != undefined){
						prevTr.find("input").last().focus().select();
					}
				}
			});
		});
		function check(){
			var array = [];
			$("table.mapping").each(function(i,n){
				var obj = {};
				
				var columns = {};
				$(n).find("tr").each(function(i, tr){
					var col = $(tr).find("input").first();
					var disp = $(tr).find("input").last();
					
					columns[col.val()] = disp.val();
				});
				obj.table = $(n).attr("name");
				obj.columns = columns;
				
				array.push(obj);
			});
			$("form input[name='columnMapping']").val(JSON.stringify(array));
			return true;
		}
	</script>
</body>
</html>